package com.lanou.shunke.admin.controller;


import com.lanou.shunke.admin.entity.*;
import com.lanou.shunke.admin.service.ArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleAction {
    @Autowired
    private ArticleService service;

    @ApiOperation("查看所有文章")
    @GetMapping("/showAll")
    public List<AllArticle> showAllArticle(@RequestParam(defaultValue = "1") int pageNum,
                                           @RequestParam(defaultValue = "10") int pageSize) {
        List list = service.selectAllArticle(pageNum, pageSize);
        return list;
    }

    @ApiOperation("通过文章ID查询该文章")
    @GetMapping("/showArticle")
    public List<AllArticle> showArticle(String articleId) {
        System.out.println(service.showArticle(articleId));
        return service.showArticle(articleId);
    }


    @ApiOperation("按照文章分类查询")
    @GetMapping("/byType")
    public List<Article> selectArticelByType(@RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize, int type) {
        List list = service.selectArticelByType(pageNum, pageSize, type);
        return list;
    }

    @ApiOperation("查看举报文章")
    @GetMapping("/report")
    public List<Article> selectReportArticle(@RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize) {
        List list = service.selectReportArticle(pageNum, pageSize);
        return list;
    }

    @ApiOperation("对举报的文章进行封禁")
    @GetMapping("/banArticle")
    public void banArt(String articleId) {
        service.banByUid(articleId);
    }

    @ApiOperation("查看被封禁文章")
    @GetMapping("/showBan")
    public List<Article> selectBan(@RequestParam(defaultValue = "1") int pageNum,
                                   @RequestParam(defaultValue = "10") int pageSize) {
        return service.selectBan(pageNum, pageSize);
    }

    @ApiOperation("对封禁的文章解封")
    @GetMapping("/Unsealing")
    public void UnsealingArt(String articleId) {
        service.UnsealingByArtID(articleId);
    }

    @ApiOperation("查看文章分类")
    @GetMapping("/type")
    public List<ArticleClassification> selectType() {
        return service.selectType();
    }

    @ApiOperation("修改文章分类")
    @GetMapping("/updateType")
    public void updateType(int typeId, String typeName) {
        service.updateType(typeId, typeName);
    }

    @ApiOperation("查看被举报的评论")
    @GetMapping("/comment")
    public List<ArticleComment> showComment(@RequestParam(defaultValue = "1") int pageNum,
                                            @RequestParam(defaultValue = "15") int pageSize) {
        return service.selectComment(pageNum, pageSize);
    }

    @ApiOperation("处理被举报的评论(修改状态)")
    @GetMapping("/delComment")
    public void delComment(String articleCommentId) {
        service.delComment(articleCommentId);
    }

    @ApiOperation("查看文章被举报的回复")
    @GetMapping("/showReply")
    public List<ArticleReply> showReply() {
        return service.showReply();
    }

    @ApiOperation("对文章被举报的回复进行处理")
    @GetMapping("/delReply")
    public void delComment(long articleReplyId) {
        service.delReplyById(articleReplyId);
    }


}
